package com.zzyl.controller.security;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.MenuVo;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/resource")
@Api(tags = "资源管理")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @ApiOperation(value = "资源列表")
    @PostMapping("/list")
    public ResponseResult<List<ResourceVo>> selectList(@RequestBody ResourceDto dto) {
        log.info("资源列表:{}", dto);
        List<ResourceVo> list = resourceService.findResourceList(dto);
        return ResponseResult.success(list);
    }

    @ApiOperation(value = "资源树形")
    @PostMapping("/tree")
    public ResponseResult<TreeVo> resourceTree(@RequestBody ResourceDto dto) {
        log.info("资源树形:{}", dto);
        TreeVo treeVo = resourceService.resourceTree(dto);
        return ResponseResult.success(treeVo);
    }

    @ApiOperation(value = "资源添加")
    @PutMapping
    public ResponseResult<Void> addResource(@RequestBody ResourceDto dto) {
        log.info("资源添加:{}", dto);
        resourceService.addResource(dto);
        return ResponseResult.success();
    }


    @PatchMapping
    @ApiOperation(value = "资源修改", notes = "资源修改")
    public ResponseResult<Void> updateResource(@RequestBody ResourceDto resourceDto) {
        resourceService.updateResource(resourceDto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "启用禁用", notes = "启用禁用")
    @PostMapping("/enable")
    public ResponseResult<Void> isEnable(@RequestBody ResourceVo resourceVo) {
        resourceService.isEnable(resourceVo);
        return ResponseResult.success();
    }

    @ApiOperation("删除菜单")
    @DeleteMapping("/{resourceNo}")
    public ResponseResult<Void> remove(@PathVariable("resourceNo") String resourceNo) {
        resourceService.deleteByResourceNo(resourceNo);
        return ResponseResult.success();
    }

    @GetMapping("/menus")
    @ApiOperation("我的菜单")
    public ResponseResult<List<MenuVo>> getMyMenus() {
        log.info("我的菜单");
        List<MenuVo> menus = resourceService.getMyMenus();
        return ResponseResult.success(menus);
    }



}
